package Manger;

import MySQL_im2.getInfo;
import Warning.ShowUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class CreateUIL extends JFrame implements MouseListener{
    getInfo info = new getInfo();
    ImageIcon img;
    int width = 500;
    int height = 500;
    JButton login = new JButton("登录");
//    JButton register = new JButton("注册");
    JTextField inputName = new JTextField();
    JPasswordField inputPass = new JPasswordField();
    JLabel name = new JLabel("管理员");
    JLabel pass = new JLabel("密码");
    public CreateUIL(String path,String t){
        img = new ImageIcon(path);
        JLabel title = new JLabel(t,SwingConstants.CENTER);
        title.setFont(new Font("华文行楷",Font.BOLD,26));
        JLabel label=new JLabel(img);
        label.setSize(img.getIconWidth(),img.getIconHeight());
        label.setBounds(0,0, img.getIconWidth(), img.getIconHeight());
        title.setBounds(width/8,height/10,width/4*3,height/10);
        setVisible(true);
        setTitle("中医体制管理系统（管理者界面）");
        setBounds(300,300,width,height);
        setLayout(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
//        登录按钮
        login.setBounds(width/4,height/2,width/2,height/18);
        login.addMouseListener(this);
        getContentPane().add(login);
//        注册按钮
//        register.setBounds(width/2,height/2,width/5,height/10);
//        register.addMouseListener(this);
//        getContentPane().add(register);
//        姓名与密码
        name.setBounds(height/5,height/4,width/10,height/15);
        getContentPane().add(name);
        pass.setBounds(height/5,40+height/4,width/10,height/15);
        getContentPane().add(pass);
//        输入框
        inputName.setBounds(width/3,height/4,width/2,height/15);
        getContentPane().add(inputName);
        inputPass.setBounds(width/3,40+height/4,width/2,height/15);
        getContentPane().add(inputPass);
        getContentPane().add(title);
        getContentPane().add(label);
    }
    public void mouseClicked(MouseEvent e){
        Object obj= e.getSource();
        if(obj==login){
            info.Found(inputName.getText(),String.valueOf(inputPass.getPassword()),"登录");
            if(info.found){
                JTableDemo manger = new JTableDemo();
                dispose();
                ShowUI showUI = new ShowUI("登陆成功","登陆成功，欢迎回来！");
            }else {
                ShowUI showUI = new ShowUI("登录失败","用户名或密码有误");
            }
        }
    }
    public void mousePressed(MouseEvent e){}
    public void mouseReleased(MouseEvent e){}
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
}

